// import React from "react";
import { Bi } from "@/module-00-codebase/pkg-01-container";
import { BaseElmt } from "@/module-00-codebase/pkg-03-abstract";
import { Field } from "@/module-00-codebase/pkg-08-entity/field-entity";
export default abstract class BaseDataField extends BaseElmt<[Field | [string, string], any]> {
  public getField = Bi.utils.createGetter(() => {
    const fieldOrStrs = this.getParams(0);
    if (Array.isArray(fieldOrStrs)) {
      const field = Bi.propertyDescription.get(fieldOrStrs[0], fieldOrStrs[1]);
      return field;
    } else {
      return fieldOrStrs;
    }
  });
  public getData() {
    return this.getParams(1);
  }
  public getValue() {
    return this.getField().getter(this.getData());
  }
  public setValue(value: any) {
    this.getField().setter(this.getData(), value);
    this.elmtRefresh();
  }
  public async validate() {
    const msg = await this.getField().validate(this.getData());
    if (msg !== this.__validationMsg) {
      this.__validationMsg = msg;
      this.elmtRefresh();
    }
    return msg;
  }
  private __validationMsg = "";
}
